from src.model.shufflenet_v2 import ShuffleNet_V2
from src.utils import Data

# 加载模型测试
if __name__ == '__main__':
    filename = r"F:\临时存放地\formal_data\HER2\first_generation\train\20X"
    batch_size = 40
    epochs = 50

    model_path = "../../resources/weights/" + str(3) + '_ShuffleNet_V2_model.h5'
    shuffleNet_V2 = ShuffleNet_V2()
    model = shuffleNet_V2.build(input_shape = (256, 256, 3), classes = 4)
    model.compile(loss='categorical_crossentropy', optimizer='sgd', metrics=['accuracy'])
    model.load_weights(model_path)
    # model = load_model(model_path)

    data = Data()
    all_loss = 0
    all_metrics = 0
    for index, trained_imgs, trained_label in data.read_image(filename, batch_size):
        x_train = trained_imgs
        y_train = trained_label[0]
        # model.train_on_batch(x_train, y_train)

        x_test = x_train
        y_test = y_train
        loss_and_metrics = model.evaluate(x_test, y_test, batch_size=batch_size)
        # print(loss_and_metrics)
        print("测试第%d批，loss值:%f" % (index, loss_and_metrics[0]))
        print("测试第%d批，metrics值:%f" % (index, loss_and_metrics[1]))
        all_loss += loss_and_metrics[0]
        all_metrics += loss_and_metrics[1]

    print("平均loss值:%f" % (all_loss / index))
    print("平均metrics值:%f" % (all_metrics / index))
